// 微信小程序API
import req from './axios'
import CONFIG from '../../config/config.config'
const $API = 'https://api.q.qq.com'

const qqConfig = {
  appid: CONFIG.qqAppid,
  secret: CONFIG.qqSecret,
}

// 接口调用凭证
const getAccessToken = data => req.get(
  `${$API}/cgi-bin/token`,
  {
    ...wechatConfig,
    ...data,
  }
);

// 根据前端发送code获取用户session等信息
const codeToSession = data => req.get(
  `${$API}/sns/jscode2session`,
  {
    ...qqConfig,
    ...data,
  }
);

// 发送模板消息
const sendMuban = data => req.post(
  `${$API}/cgi-bin/message/wxopen/template/send?access_token=${data.access_token}`,
  {
    ...wechatConfig,
    ...data,
  }
);

// 发送订阅消息
const sendDingyue = data => req.post(
  `${$API}/cgi-bin/message/subscribe/send?access_token=${data.access_token}`,
  {
    ...wechatConfig,
    ...data,
  }
);

export default {
  getAccessToken,
  codeToSession,
  sendMuban,
  sendDingyue,
}